define(['../../../carrys/jsonList','../../../../../js/lib/other/sweet-alert'],function(jsonData) {
    return ['$scope','$location', '$interval','$timeout','$routeParams','bizProxy', function($scope,$location,$interval,$timeout,$routeParams,bizProxy) {
		$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','36');//显示底部文字
    	
    	//默认值
    	$scope.jsonList = jsonData;
    	$scope.creditorType = "";$scope.applicantType = "";$scope.idType = "";
    	
    	if($routeParams.flag != "" && $routeParams.flag != null){
    		queryLoanApplyOutline($routeParams.flag);
    	}
    	
    	//点击确认修改
    	$scope.confirmEdit = function(){
    		if(! $scope.inviteCode){
    			$scope.$emit("promptAlertMsg","律师推荐码不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}
    		else if(! $scope.applicantType){
    			$scope.$emit("promptAlertMsg","申请人类别不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}else if(! $scope.applyName){
    			$scope.$emit("promptAlertMsg","申请人不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}else if(! $scope.idType){
    			$scope.$emit("promptAlertMsg","证件类别不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}else if(! $scope.documentsNo){
    			$scope.$emit("promptAlertMsg","证件号码不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}else if(! $scope.loanAmount){
    			$scope.$emit("promptAlertMsg","贷款金额不能为空");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
                return;
    		}else{
    			if(!_YHC_util.IdentityCodeValid($scope.documentsNo) && $scope.idType === '1'){
    				$scope.$emit("promptAlertMsg","无效身份证号");
        			$scope.$emit("showCollect",true);
        			$timeout(function(){
        				$scope.$emit("showCollect",false);
        			},transData.promptTime);
                    return;
    			}else{
    				if(!_YHC_util.IdentityCodeValid($scope.documentsNo) && $scope.idType === '1'){
	    				$scope.$emit("promptAlertMsg","无效身份证号");
	        			$scope.$emit("showCollect",true);
	        			$timeout(function(){
	        				$scope.$emit("showCollect",false);
	        			},transData.promptTime);
	                    return;
	    			}else{
	    				submitApplyFor();
	    			}
    				
    			}
    		}
    	}
    	
    	//点击撤销申请
    	$scope.cancleApply = function(){
    		var sweetData = {
					title : "",
					text : "确认要撤销申请吗？",
					type : "",
					showCancelButton : true,
					closeOnConfirm : false
				};
    		FIREFLY(sweetData,function(){
				$timeout(function(){
					cancelLoanApply();
				},0);
			},function(){return;});
    	}
    	
    	//提交申请到代理
    	function submitApplyFor(){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
//        	bizInfo.caseName = $scope.caseName;
        	bizInfo.loanApplyId = $routeParams.flag;
        	bizInfo.inviteCode = $scope.inviteCode;
        	bizInfo.applyUserType = $scope.applicantType;
        	bizInfo.applyUserName = $scope.applyName;
        	bizInfo.idType = $scope.idType;
        	bizInfo.idNo = $scope.documentsNo;
        	bizInfo.loanAmount = $scope.loanAmount;
        	bizInfo.debtType = ($scope.creditorType == "" || $scope.creditorType == null)?"":$scope.creditorType;
        	bizInfo.caseNo = $scope.caseNo;
        	bizInfo.caseAmount = $scope.caseQuan;
        	
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("changeLoanApply",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			$scope.$emit("loadingChange",false);
						$timeout(function(){
							$scope.$emit("goNext","/sucLoanApply");
						},0);
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChange', false);
		    				$scope.$emit("promptAlertMsg","连接超时");
		    				$scope.$emit("showCollect",true);
		    				$timeout(function(){
		    					$scope.$emit("showCollect",false);
		    				},transData.promptTime);
		    			}
		    		});
    	}
    	
    	//调用代理接口撤销贷款申请
    	function cancelLoanApply(){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.applyId = $routeParams.flag;
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("cancelLoanApply",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			$timeout(function(){
							$scope.$emit("loadingChange",false);
							history.back();
						},0);
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChange', false);
		    				$scope.$emit("promptAlertMsg","连接超时");
		    				$scope.$emit("showCollect",true);
		    				$timeout(function(){
		    					$scope.$emit("showCollect",false);
		    				},transData.promptTime);
		    			}
		    		});
    	}
    	
    	//调用代理接口获取数据
    	function queryLoanApplyOutline(applyId){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.applyId = applyId;
    		$scope.$emit("loadingChange",true);
    		bizProxy.queryProxyBizData("queryLoanApplyOutline",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
		    			if(tempData.body != "" && tempData.body != null && tempData.body != "[]"){
							$timeout(function(){
								$scope.$emit("loadingChange",false);
								var loanData = JSON.parse(tempData.body);
								$scope.reason = loanData.reason;
								$scope.inviteCode = loanData.inviteCode;
						    	$scope.applicantType = loanData.applyUserType;
						    	$scope.applyName = loanData.applyUserName;
						    	$scope.idType = loanData.idType;
						    	$scope.documentsNo = loanData.idNo;
						    	$scope.loanAmount = loanData.loanAmount;
						    	$scope.creditorType = loanData.debtType;
						    	$scope.caseNo = loanData.caseNo;
						    	$scope.caseQuan = loanData.caseAmount;
		//				    	$scope.caseName = loanData.caseTopic;
							},0);
						}else{
							$scope.$emit("loadingChange",false);
							$scope.$emit("promptAlertMsg","未查找到相关数据");
							$scope.$emit("showCollect",true);
							$timeout(function(){
								$scope.$emit("showCollect",false);
								history.back();
							},transData.promptTime);
						}
		    		},function(data){
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChange",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
									history.back();
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit('loadingChange', false);
		    				$scope.$emit("promptAlertMsg","连接超时");
		    				$scope.$emit("showCollect",true);
		    				$timeout(function(){
		    					$scope.$emit("showCollect",false);
		    					history.back();
		    				},transData.promptTime);
		    			}
		    		});
    	}
        $scope.$apply();
    }];
});